test(tests): add BLOCKHASH genesis hash availability test#2228
test(tests): add BLOCKHASH genesis hash availability test#2228marioevz merged 2 commits intoethereum:mainfrom
Conversation
|
CC @rakita who asked for such a test (upstream fix PR bluealloy/revm#3024) |
|
Would be great to add additional block, and in block 2 to fetch block 1 hash, so that we can test both genesis and first executed block insertion. |
LouisTsai-Csie
left a comment
There was a problem hiding this comment.
The current test structure looks good, but it is worth considering @rakita’s suggestion to include an additional scenario.
Add regression test verifying BLOCKHASH(0) returns genesis hash in block 1. Tests blockchain test infrastructure properly populates genesis hash before execution, preventing BLOCKHASH(0) from returning 0. Regression context: revm blockchaintest runner wasn't inserting block_hashes into state, causing BLOCKHASH(0) to return 0. This broke tests with dynamic address computations like BLOCKHASH(0) | TIMESTAMP, where the computed address would be incorrect, leading to balance transfer failures. Test validates infrastructure setup by storing ISZERO(BLOCKHASH(0)) which should be 0 (false) when genesis hash is properly available.
a9e1ac7 to
50adff8
Compare
Extends test_genesis_hash_available to verify both genesis (block 0) and first executed block (block 1) hash insertion by adding a second block that calls the contract, testing BLOCKHASH(0) and BLOCKHASH(1). Addresses PR feedback to test complete block hash infrastructure. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Thank you for your feedback. I have updated the test accordingly such that after both blocks in the test are executed, the storage at key 0, 1 are expected to be zero (as per the logic of iszero(blockhash(0)) and iszero(blockhash(1))). Hope this change is fine @LouisTsai-Csie 🙏 |
) * test(tests): add BLOCKHASH genesis hash availability test Add regression test verifying BLOCKHASH(0) returns genesis hash in block 1. Tests blockchain test infrastructure properly populates genesis hash before execution, preventing BLOCKHASH(0) from returning 0. Regression context: revm blockchaintest runner wasn't inserting block_hashes into state, causing BLOCKHASH(0) to return 0. This broke tests with dynamic address computations like BLOCKHASH(0) | TIMESTAMP, where the computed address would be incorrect, leading to balance transfer failures. Test validates infrastructure setup by storing ISZERO(BLOCKHASH(0)) which should be 0 (false) when genesis hash is properly available. * test(tests): extend BLOCKHASH test to verify block 1 hash availability Extends test_genesis_hash_available to verify both genesis (block 0) and first executed block (block 1) hash insertion by adding a second block that calls the contract, testing BLOCKHASH(0) and BLOCKHASH(1). Addresses PR feedback to test complete block hash infrastructure. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
🗒️ Description
Add minimal regression test for BLOCKHASH opcode to verify genesis hash availability in blockchain tests. This test ensures that
BLOCKHASH(0)returns the genesis hash (non-zero value) when executed in block 1, validating that blockchain test infrastructure properly initializes theblock_hashesmapping before execution.Context: This is a regression test for a bug found in the revm blockchaintest runner where
block_hashesweren't being populated, causingBLOCKHASH(0)to incorrectly return 0. This broke tests using dynamic address computations likeBLOCKHASH(0) | TIMESTAMP, where the computed address would be wrong, leading to test failures.The test validates infrastructure correctness by:
ISZERO(BLOCKHASH(0))in a contract deployed in block 1🔗 Related Issues or PRs
N/A.
✅ Checklist
toxchecks to avoid unnecessary CI fails, see also Code Standards and Enabling Pre-commit Checks:uvx --with=tox-uv tox -e lint,typecheck,spellcheck,markdownlinttype(scope):.mkdocs servelocally and verified the auto-generated docs for new tests in the Test Case Reference are correctly formatted.@ported_frommarker.📝 Additional Notes
File Added:
tests/frontier/opcodes/test_blockhash.pytest_genesis_hash_available(57 lines)Quality Checks Passed:
ruff check- no linting issuesruff format- properly formattedmypy- no type errorsuv run fill --fork=Frontier- generates valid fixturesuv run fill --fork=Cancun- works across all forksSuggested PR Title: